package com.suray.basic.wcs.plc.pojo.oper.single;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

public class TurnoverOper extends DeviceBase {
    private static final PlcOffset UPPER_LIMIT = new PlcOffset(0, 0);
    private static final PlcOffset LOWER_LIMIT = new PlcOffset(0, 1);
    private static final PlcOffset RUN_ING = new PlcOffset(0, 2);
    private static final PlcOffset IS_ERROR = new PlcOffset(0, 3);
    private static final PlcOffset OVER_TIME = new PlcOffset(0, 4);
    private static final PlcOffset LOCK = new PlcOffset(0, 5);

    public TurnoverOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                        Location location, Coord lockLocation, long deviceId, Integer gridzMax, Integer gridzRelative,
                        int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation, deviceId, gridzMax,
                gridzRelative, plcId);
    }

    public boolean isUpperLimit() {
        return readPlc(UPPER_LIMIT) == 1;
    }

    public boolean isLowerLimit() {
        return readPlc(LOWER_LIMIT) == 1;
    }

    public boolean isRuning() {
        return readPlc(RUN_ING) == 1;
    }

    public boolean isError() {
        return readPlc(IS_ERROR) == 1;
    }

    public boolean isOverTime() {
        return readPlc(OVER_TIME) == 1;
    }

    public boolean isLock() {
        return readPlc(LOCK) == 1;
    }


    @Override
    public String toString() {
        return "Station{" +
                "deviceName=" + getDeviceName() +
                ", upperLimit=" + isUpperLimit() +
                ", lowerLimit=" + isLowerLimit() +
                ", runing=" + isRuning() +
                ", isError=" + isError() +
                ", overTime=" + isOverTime() +
                ", isLock=" + isLock() +
                '}';
    }
}
